<template>
  <el-dialog
    title="邮件内容"
    :visible.sync="dialogValue"
    :close-on-click-modal="false"
    append-to-body
    width="1000px"
    top="5vh"
  >
    <SubmitForm
      disabled
      :rule-form="ruleForm"
      :rules="rules"
      :form-list="formList"
      @change="handleFormChange"
      @save="onSave"
      @close="dialogValue = false"
    >
      <template v-slot:content>
        <div v-html="ruleForm.content"></div>
      </template>
      <template v-slot:footer>
        <div></div>
      </template>
    </SubmitForm>

  </el-dialog>
</template>

<script>
import { http } from '@/api'
export default {
  name: 'FormAdd',
  data() {
    return {
      apiKey: 'email',
      dialogValue: false,
      ruleForm: {
      },
      defaultForm: {
      },
      rules: {
      },
      formList: [
        {
          key: 'content',
          label: '',
          slot: true
        }
      ]
    }
  },
  methods: {
    handleFormChange({ key, val }) {

    },
    open(row) {
      this.dialogValue = true
      if (row) {
        http[this.apiKey].read(row.id).then(res => {
          this.ruleForm = {
            ...res.data
          }
        })
      } else {
        this.ruleForm = {
          ...this.defaultForm
        }
      }
    },
    onSave() {
      http[this.apiKey][this.ruleForm.id ? 'update' : 'create'](this.ruleForm.id, { ...this.ruleForm }).then(res => {
        this.$message.success('操作成功')
        this.dialogValue = false
        this.$emit('get-page')
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
